﻿using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace furion.blog.Domain.Query.AreaCode
{
    public class AreaCodeDetailQuery : BaseDetailQuery<furion.blog.Domain.MySQL.AreaCode>
    {


        public long? Code { get; set; } = null;
        /// <summary>
        /// 父级code
        /// </summary>
        public long? Pcode { get; set; } = 0L;
        public string Name { get; set; } = string.Empty;
        public byte? Level { get; set; } = null;


        public override string[] IgnoreColumns() {
            return new string[] { "ts" };
        }

        public override (Expression<Func<furion.blog.Domain.MySQL.AreaCode, object>>, OrderByType) OrderBy()
        {
            return ((t) => t.Code, OrderByType.Asc);
        }

        /// <summary>
        /// 查询表达式
        /// </summary>
        /// <returns></returns>
        public override Expression<Func<furion.blog.Domain.MySQL.AreaCode, bool>> Exp()
        {
            var exp = Expressionable.Create<furion.blog.Domain.MySQL.AreaCode>();
            exp.AndIF(Code != null, t => t.Code == Code);
            exp.AndIF(Pcode != null, t => t.Pcode == Pcode);
            exp.AndIF(Level != null, t => t.Level == Level);

            if (!FuzzyQuery)
            {
                exp.AndIF(!string.IsNullOrWhiteSpace(Name), t => t.Name == Name);
            }
            else
            {
                exp.AndIF(!string.IsNullOrWhiteSpace(Name), t => t.Name.Contains(Name));
            }
            return exp.ToExpression();
        }

    }
}
